﻿using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.SessionState;
using Newtonsoft.Json;
using XinBang.ShoppingCart;

namespace XinBang.Web
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ShoppingCartServices : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            Results r = new Results();
            r.Flag = false;
            Cart cart = Cart.GetShoppingCart();
            if (!string.IsNullOrEmpty(context.Request.QueryString["id"]))
            {
                cart.RemoveGoodsFromCart(Convert.ToInt32(context.Request.QueryString["id"]));
                r.Flag = true;
            }
            
            context.Response.Write(JavaScriptConvert.SerializeObject(r));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private class Results
        {
            private bool flag;

            public bool Flag
            {
                get { return flag; }
                set { flag = value; }
            }
        }
    }
}
